package com.ruoyi.syf.config.aspectj;

import com.ruoyi.common.annotation.DeleteTask;
import com.ruoyi.syf.service.IRiskCheckTaskService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 删除定时任务aop
 */
@Deprecated
@Aspect
@Component
public class DeleteTaskAspect {

    @Autowired
    private IRiskCheckTaskService checkTaskService;

    @Pointcut("@annotation(com.ruoyi.common.annotation.DeleteTask)")
    public void processParameters() {
    }

    @AfterReturning(value = "processParameters()", returning = "res")
    public void afterReturning(JoinPoint joinPoint, Boolean res) {
        if (!res) {
            return;
        }
        Object[] args = joinPoint.getArgs();
        if (args == null || args.length == 0) {
            return;
        }
        Signature signature = joinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature) signature;
        Method method = methodSignature.getMethod();
        DeleteTask deleteTask = method.getAnnotation(DeleteTask.class);
        //获取ID
        Long[] ids = (Long[]) args[0];
//        List<Long> taskIds = checkTaskService.getIds(ids,deleteTask.value());
//        checkTaskService.deleteByIds(taskIds);
    }


}
